<template>
  <section>
    <news-header @headChange="handleHeadChange"></news-header>
    <news-list :list-data="listData"></news-list>
  </section>
</template>

<script setup lang="ts">
import { defineProps, reactive, ref } from "vue";
import ajax from "@/util/request";
import NewsList from "../news/news-list.vue";
import NewsHeader from "./news-header.vue";

const props = defineProps({
  id: {
    type: String,
  },
});

const listData = reactive<any>([]);

const selectId = ref(0);

// watch(
//   selectId,
//   (newVal:any) => {
//     console.log("有新的id传入：", newVal);
//     ajax("/content/queryList", { t_cat_plant_fk: newVal, rows: 10 }).then(
//       (res:any) => {
//         // listData = res.data.result_data;
//         listData.length = 0;
//         listData.push(...res.data.result_data)
//         console.log("listData = ",listData);
//       }
//     );
//   },
//   {immediate: true}
// );

function handleHeadChange(itemId: any) {
  // selectId.value = itemId;
  ajax("/content/queryList", { t_cat_plant_fk: itemId, rows: 10 }).then(
    (res: any) => {
      // listData = res.data.result_data;
      listData.length = 0;
      listData.push(...res.data.result_data);
      console.log("listData = ", listData);
    }
  );
}
</script>

